function a(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

var t = require("../../utils/api.js"), e = require("../../utils/disapi.js"), o = getApp();

Page({
    data: {
        p_type: [],
        curid: "",
        windowHeight: "",
        info: [],
        show: !1,
        title: "",
        class_title: "",
        page: 2,
        searchLoading: !1,
        searchLoadingComplete: !1,
        pid: "",
        footer: [],
        carnum: "",
        one: [],
        two: [],
        open_search: 2,
        showLoding: !0,
        showlodingmore: {
            showMore: !1,
            noMore: !1
        },
        showSuccesstipInfo: {
            showSuccesstip: !0,
            title: "已加入购物车",
            type: !0
        },
        showCount: 10,
        mid: !1,
        default_small_img: o.globalData.default_small_img,
        playBtn: "/images/playvideo.png",
        all: 1
    },
    onLoad: function(a) {
        var e = this, s = a;
        if (o.globalData.openid) if (s && s.mid) {
            var n = s.mid, i = {
                openid: o.globalData.openid,
                head_mid: n
            };
            t.selectShareHead(i).then(function(a) {
                console.log(a), 0 == a.errno && (e.setData({
                    head: a.data
                }), e.loads(s));
            });
        } else e.loads(s); else if (console.log(s), s.mid) var n = s.mid, d = setInterval(function() {
            if (o.globalData.openid) {
                clearInterval(d), t.getMember({
                    openid: o.globalData.openid
                }).then(function(a) {
                    console.log(a);
                });
                var a = {
                    openid: o.globalData.openid,
                    head_mid: n
                };
                t.selectShareHead(a).then(function(a) {
                    console.log(a), 0 == a.errno && e.setData({
                        head: a.data
                    }), e.loads(s);
                });
            } else ;
        }, 100); else e.loads(s);
    },
    loads: function(s) {
        var n = this, i = t.getfooter(), d = s.p_id ? s.p_id : "", l = s.pid ? s.pid : "", r = "showlodingmore.showMore";
        if (s.mid && n.setData({
            showToIndex: !0
        }), "" != d && void 0 != d) {
            var g = o.globalData.openid;
            e.get_group_bing({
                openid: g,
                pid: d
            }).then(function(a) {
                console.log(a);
            });
        }
        if (n.setData(a({
            showLoding: !n.data.showLoding
        }, r, !1)), n.setData({
            default_img_small: o.globalData.default_small_img,
            default_img_big: o.globalData.default_big_img,
            is_open_video: o.globalData.is_open_goods_video,
            data_end_show_img_open: o.globalData.data_end_show_img_open,
            data_end_show_img: o.globalData.data_end_show_img
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), t.getCartNum({
            openid: o.globalData.openid
        }).then(function(a) {
            console.log(a), wx.setStorageSync("cartnum", a.data), n.setData({
                carnum: wx.getStorageSync("cartnum")
            });
        }), n.setData({
            footer: i
        }), t.getMember({
            openid: o.globalData.openid
        }).then(function(a) {
            n.setData({
                member: a.data
            });
        }), "" != s.mid && null != s.mid && void 0 != s.mid) {
            o.globalData.share_mid = s.mid, o.globalData.share_url = "/pages/template/classify";
            c = {
                openid: wx.getStorageSync("openid"),
                head_mid: o.globalData.share_mid
            };
            t.selectShareHead(c).then(function(a) {
                console.log(a), 0 == a.errno && wx.setStorage({
                    key: "head_info",
                    data: a.data
                });
            });
        }
        o.globalData.go = 1, o.globalData.openid = wx.getStorageSync("openid"), t.getTeamOpenid({
            openid: o.globalData.openid
        }).then(function(a) {
            console.log(a), "" == a.data.user.m_head_openid ? wx.reLaunch({
                url: "/pages/group/groupList"
            }) : n.setData({
                head: a.data.head_info,
                member: a.data.user
            });
        });
        r = "showlodingmore.showMore";
        if (console.log(l), l) {
            c = {
                pid: l,
                openid: o.globalData.openid
            };
            n.setData({
                all: 0,
                pid: l
            });
        } else var c = {
            openid: o.globalData.openid,
            type: 2
        };
        t.getClassify(c).then(function(t) {
            if (console.log(t), n.setData(a({
                showLoding: !n.data.showLoding
            }, r, !1)), t.data.goods.length < n.data.showCount) {
                var e;
                n.setData((e = {}, a(e, r, !1), a(e, "showlodingmore.noMore", !0), a(e, "stopscroll", !0), 
                e));
            }
            0 == t.errno && n.setData({
                one: t.data.one,
                three: t.data.goods,
                two: t.data.two,
                open_search: t.data.open_search.value,
                status: t.data.goods_cate_show_type,
                class_title: "商品分类"
            }), t.data.goods.length >= 5 ? n.setData({
                searchLoading: !0,
                searchLoadingComplete: !1
            }) : n.setData({
                searchLoading: !1,
                searchLoadingComplete: !0
            });
        }), wx.getSystemInfo({
            success: function(a) {
                var t = a.windowHeight - 10;
                n.setData({
                    windowHeight: t
                }), console.log(a);
            }
        });
    },
    onShareAppMessage: function(a) {
        var t = this;
        return console.log("/pages/template/classify?mid=" + t.data.head.m_id + "&&p_id=" + t.data.member.m_id), 
        {
            title: t.data.class_title,
            path: "/pages/template/classify?mid=" + t.data.head.m_id + "&&p_id=" + t.data.member.m_id + "&&pid=" + t.data.pid,
            success: function(a) {},
            fail: function(a) {
                wx.showToast({
                    title: "分享失败",
                    icon: "clear",
                    duration: 2e3
                });
            }
        };
    },
    switchRightTab: function(e) {
        var s = this;
        o.globalData.go = 1, s.setData({
            showLoding: !s.data.showLoding,
            "showlodingmore.showMore": !1
        }), s.setData({
            searchLoading: !1,
            searchLoadingComplete: !1
        });
        var n = e.currentTarget.dataset.id, i = e.currentTarget.dataset.in, d = e.currentTarget.dataset.k;
        if (console.log(n, i, d), s.setData({
            pid: n,
            page: 2
        }), console.log(n), -1 == n) l = {
            openid: o.globalData.openid,
            type: 2
        }; else var l = {
            pid: n,
            openid: o.globalData.openid
        };
        console.log(l);
        var r = "showlodingmore.noMore";
        t.getClassify(l).then(function(t) {
            if (console.log(t), t.data.goods.length < s.data.showCount) {
                var e;
                s.setData((e = {}, a(e, "showlodingmore.showMore", !1), a(e, r, !0), e));
            } else {
                var o;
                s.setData((o = {}, a(o, "showlodingmore.showMore", !1), a(o, r, !1), o));
            }
            s.setData({
                one: t.data.one,
                three: t.data.goods,
                two: t.data.two,
                open_search: t.data.open_search.value,
                all: -1 == n ? 1 : 0
            }), console.log(t.data.two), t.data.goods.length >= 10 ? s.setData({
                searchLoading: !0,
                searchLoadingComplete: !1
            }) : s.setData({
                searchLoading: !1,
                searchLoadingComplete: !0
            });
            var i = "";
            for (var d in t.data.one) t.data.one[d].select && (i = t.data.one[d].gc_name);
            for (var l in t.data.two) t.data.two[l].select && (i = i + "-" + t.data.two[l].gc_name);
            s.setData({
                showLoding: !s.data.showLoding,
                scrolltop: 0,
                class_title: i
            });
        });
    },
    tab_more: function() {
        this.setData({
            show: !0
        });
    },
    closeButton: function() {
        this.setData({
            show: !1
        });
    },
    add: function(e) {
        for (var o = this, s = o.data.three, n = e.currentTarget.dataset.id, i = {
            gid: n,
            num: 1,
            openid: wx.getStorageSync("openid")
        }, d = 0; d < s.length; d++) {
            var l = "three[" + d + "].curGoodsNum", r = o.data.three[d].curGoodsNum, g = o.data.three[d].g_limit_num, c = o.data.three[d].sum;
            c = parseInt(c), g = parseInt(g), r = parseInt(r);
            var p = Math.min(g, c);
            if (s[d].g_id == n) {
                if (console.log(r), r < p && g > 0) o.setData(a({}, l, r + 1)); else if (r < c && 0 == g) o.setData(a({}, l, r + 1)); else {
                    if (r >= g) return console.log(g, r), void wx.showToast({
                        title: "商品限购" + g + "件哦",
                        icon: "none",
                        duration: 2e3
                    });
                    if (r >= c) return void wx.showToast({
                        title: "商品数量没有那么多了",
                        icon: "none",
                        duration: 2e3
                    });
                }
                break;
            }
        }
        t.addCart(i).then(function(a) {
            console.log(a.data), 0 == a.errno ? (console.log(0), o.successtip(), wx.setStorageSync("cartnum", a.data.count), 
            o.setData({
                carnum: a.data.count
            }), 0 != a.data.count ? (wx.showTabBarRedDot({
                index: 2
            }), wx.setTabBarBadge({
                index: 2,
                text: a.data.count + ""
            })) : wx.hideTabBarRedDot({
                index: 2
            })) : wx.showToast({
                title: a.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    onCloseButton: function(a) {
        this.setData({
            specShow: !this.data.specShow
        });
    },
    specOnChange: function(a) {
        console.log(a);
        var t = a.detail, e = this, o = e.data.specDetail;
        o.num = t, e.setData({
            specDetail: o
        });
    },
    addSpec: function(a) {
        console.log(a);
        var e = this, s = o.globalData.openid, n = a.currentTarget.dataset.id, i = a.currentTarget.dataset.atid;
        t.GetSpecInfo({
            openid: s,
            id: n
        }).then(function(a) {
            if (0 == a.errno) {
                var o = [], n = [];
                console.log(a.data.spec);
                for (var d in a.data.spec) {
                    var l = [], r = [];
                    n[d] = {
                        id: a.data.spec[d].id,
                        subSpec: a.data.spec[d].item[0].gsi_id
                    };
                    for (var g in a.data.spec[d].item) l[g] = a.data.spec[d].item[g].gsi_title, r[g] = a.data.spec[d].item[g].gsi_id;
                    o[d] = {
                        id: a.data.spec[d].id,
                        name: a.data.spec[d].title,
                        stem: l,
                        stem_id: r
                    };
                }
                for (var c = "", d = n.length - 1; d >= 0; d--) c += "," + n[d].subSpec;
                console.log(c, a.data.goods.g_id), t.GetSpecDeatail({
                    openid: s,
                    id_str: c,
                    gid: a.data.goods.g_id
                }).then(function(t) {
                    if (console.log(t), 0 == t.errno) {
                        var s = t.data.ggo_market_price.split("."), d = a.data.goods.g_limit_num <= 0 ? t.data.ggo_stock : parseInt(a.data.goods.g_limit_num) < parseInt(t.data.ggo_stock) ? a.data.goods.g_limit_num : t.data.ggo_stock, l = {
                            id: a.data.goods.g_id,
                            name: a.data.goods.g_name,
                            photo: a.data.goods.g_icon,
                            specInfo: t.data.ggo_title,
                            price: s,
                            oldPrice: t.data.ggo_old_price,
                            num: 1,
                            popup: o,
                            count: t.data.ggo_stock,
                            limit: d,
                            is_limit: a.data.goods.g_limit_num,
                            ggo_id: t.data.ggo_id
                        };
                        e.setData({
                            specDetail: l,
                            specShow: !e.data.specShow,
                            specDefault: n,
                            atid: i
                        });
                    } else wx.showToast({
                        title: a.message,
                        icon: "none"
                    });
                });
            } else wx.showToast({
                title: a.message,
                icon: "none"
            });
        });
    },
    specAddCart: function(e) {
        for (var s = this, n = e.currentTarget.dataset.id, i = e.currentTarget.dataset.optionid, d = e.currentTarget.dataset.num, l = e.currentTarget.dataset.atid, r = s.data.three, g = 0; g < r.length; g++) {
            var c = "three[" + g + "].curGoodsNum", p = s.data.three[g].curGoodsNum;
            if (r[g].g_id == n) {
                if (!(0 == r[g].g_limit_num || p < r[g].g_limit_num)) return void wx.showToast({
                    title: "本商品限购" + r[g].g_limit_num + "件",
                    icon: "none",
                    duration: 2e3
                });
                s.setData(a({}, c, parseInt(p) + 1));
                break;
            }
        }
        t.SpecAddCart({
            openid: o.globalData.openid,
            gid: n,
            ggoid: i,
            num: d,
            at_id: l
        }).then(function(a) {
            0 == a.errno ? (s.successtip(), 0 != a.data.count ? (wx.showTabBarRedDot({
                index: 2
            }), wx.setTabBarBadge({
                index: 2,
                text: a.data.count + ""
            })) : wx.hideTabBarRedDot({
                index: 2
            }), s.setData({
                specShow: !1,
                carnum: a.data.count
            }), wx.setStorageSync({
                key: "cartnum",
                data: parseInt(a.data.count)
            })) : wx.showToast({
                title: a.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    popup: function(a) {
        for (var e = this, s = a.currentTarget.dataset.id, n = a.currentTarget.dataset.subid, i = e.data.specDefault, d = "", l = i.length - 1; l >= 0; l--) i[l].id == s && (i[l].subSpec = n, 
        e.setData({
            specDefault: i
        })), d += "," + i[l].subSpec;
        var r = o.globalData.openid, g = e.data.specDetail;
        t.GetSpecDeatail({
            openid: r,
            id_str: d,
            gid: g.id
        }).then(function(a) {
            if (0 == a.errno) {
                var t = a.data.ggo_market_price.split("."), o = g.is_limit <= 0 ? a.data.ggo_stock : parseInt(g.is_limit) < parseInt(a.data.ggo_stock) ? g.is_limit : a.data.ggo_stock;
                g.specInfo = a.data.ggo_title, g.price = t, g.oldPrice = a.data.ggo_old_price, g.count = a.data.ggo_stock, 
                g.limit = o, g.ggo_id = a.data.ggo_id, e.setData({
                    specDetail: g
                });
            } else wx.showToast({
                title: res.message,
                icon: "none"
            });
        });
    },
    overlimit: function(a) {
        console.log(a);
        var t = this, e = t.data.cur_cid;
        console.log(e), void 0 == e && wx.showToast({
            title: "超出可购买数量了",
            icon: "none",
            duration: 2e3
        }), t.setData({
            delStatus: !this.data.delStatus,
            del_id: e
        });
    },
    onReachBottom: function(a) {
        console.log(1);
    },
    bindDownLoad: function() {
        var e, s = this;
        if (0 == o.globalData.go) return !1;
        if (o.globalData.go = 0, s.data.showlodingmore.noMore || s.data.showlodingmore.noMore) return !1;
        var n = s.data.pid, i = "showlodingmore.noMore", d = "showlodingmore.showMore";
        if (1 == s.data.all) l = {
            page: s.data.page,
            openid: o.globalData.openid,
            type: 2
        }; else if (1 != s.data.all) var l = {
            pid: n,
            page: s.data.page,
            openid: o.globalData.openid
        };
        console.log(s.data.all, s.data.page, s.data.pid), s.setData((e = {}, a(e, d, !0), 
        a(e, i, !1), e)), t.getClassify(l).then(function(t) {
            if (console.log(t), "0" == t.errno) {
                var e = s.data.three.concat(t.data.goods), n = s.data.page + parseInt(1);
                if (console.log(e), s.setData({
                    three: e,
                    page: n
                }), t.data.goods.length < s.data.showCount) {
                    var l;
                    s.setData((l = {}, a(l, d, !1), a(l, i, !0), l));
                }
                console.log(t.data.goods.length), console.log(t.data.goods.length), t.data.goods.length >= 10 ? s.setData({
                    searchLoading: !0,
                    searchLoadingComplete: !1
                }) : s.setData({
                    searchLoading: !1,
                    searchLoadingComplete: !0
                });
            }
            1 == t.errno && s.setData({
                searchLoading: !1,
                searchLoadingComplete: !0
            }), s.setData(a({}, d, !1)), o.globalData.go = 1;
        }), wx.hideLoading();
    },
    sites: function(a) {
        var t = this;
        console.log(a);
        var e = a.currentTarget.dataset.data_index, o = t.data.footer, s = [ "/pages/template/index", "/pages/template/classify", "/pages/template/cart", "/pages/personal/personal" ];
        "url" == o.params.data[e].type ? s.includes(o.params.data[e].url) ? wx.reLaunch({
            url: o.params.data[e].url,
            success: function() {
                t.setData({
                    showLoding: !0
                });
            }
        }) : wx.navigateTo({
            url: o.params.data[e].url,
            success: function() {
                t.setData({
                    showLoding: !0
                });
            }
        }) : "tel" == o.params.data[e].type ? wx.makePhoneCall({
            phoneNumber: o.params.data[e].url
        }) : "out_link" == o.params.data[e].type ? wx.navigateTo({
            url: "/pages/template/out_h5?url=" + o.params.data[e].url
        }) : "app" == o.params.data[e].type && wx.navigateToMiniProgram({
            appId: o.params.data[e].url_name,
            path: o.params.data[e].url,
            envVersion: "develop",
            success: function(a) {}
        });
    },
    playvideo: function(a) {
        console.log(a);
        var t = a.currentTarget.dataset.url, e = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/goods/video?url=" + t + "&id=" + e + "&resource=3"
        });
    },
    successtip: function() {
        arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
        var t = this;
        t.setData(a({}, "showSuccesstipInfo.showSuccesstip", !t.data.showSuccesstipInfo.showSuccesstip)), 
        console.log(t.data.showSuccesstipInfo.showSuccesstip), setTimeout(function() {
            t.setData(a({}, "showSuccesstipInfo.showSuccesstip", !t.data.showSuccesstipInfo.showSuccesstip));
        }, 1300);
    }
});